/*
 * MyJoinedAskListItem.java
 * business
 *
 * Created by SunDing on 2016/9/29.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;

import com.yidiandao.business.R;
import com.yidiandao.business.data.response.AskToBuyResponse;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.MyJoinedAskHolder;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.TimeUtils;
import com.yidiandao.business.utils.UIUtils;

/** 我参与的求购 */
public class MyJoinedAskListItem
        extends DisplayListItem<MyJoinedAskHolder, AskToBuyResponse.DataBean.WantListBean> {

    public MyJoinedAskListItem(AskToBuyResponse.DataBean.WantListBean s) {
        super(s);
    }

    @Override
    public void onShow(final Context context, final MyJoinedAskHolder holder) {
        //logo
        ImageLoader.loadImage(context, holder.mIvLogo, data.getPicture());
        //商品名
        holder.mTvName.setText(data.getGoodsName());
        //商品属性
        holder.mTvBrand.setText(data.getGoodsAttr());
        //求购数量
        holder.mTvNum.setText(data.getBuyNum() + data.getBuyUnit());
        //求购地址
        holder.mTvAddress.setText(data.getAddress());
        //求购说明
        holder.mTvDesc.setText(UIUtils.getString(R.string.ask_to_buy_des, data.getBuyExplain()));
        //求购时间
        holder.mTvTime.setText(
                TimeUtils.getRelativeTimeWithSingleUnit(
                        context.getResources(),
                        TimeUtils.getAndroidMillis(data.getCreateTime()),
                        true));
        //联系电话
        final String phone = data.getContactNumber();
        switch (data.getIsAccept()) {
            case "0":
                //初始状态
                holder.mLlConnectionInfo.setVisibility(View.GONE);
                holder.mIvStatus.setVisibility(View.GONE);
                break;
            case "1":
                //同意
                holder.mIvStatus.setVisibility(View.VISIBLE);
                holder.mIvStatus.setImageResource(R.mipmap.ic_ask_to_buy_agree);
                holder.mLlConnectionInfo.setVisibility(View.VISIBLE);
                holder.mTvPhone.setText(UIUtils.getString(R.string.ask_to_buy_phone1, phone));
                holder.mTvGetAddress.setText(
                        data.getProvince()
                                + data.getCity()
                                + data.getDistrict()
                                + data.getAddress());
                holder.mTvConnect.setOnClickListener(
                        new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Uri uri = Uri.parse("tel:" + phone);
                                Intent intent = new Intent(Intent.ACTION_DIAL, uri);
                                context.startActivity(intent);
                            }
                        });
                break;
            case "2":
                //拒绝
                holder.mIvStatus.setVisibility(View.VISIBLE);
                holder.mLlConnectionInfo.setVisibility(View.GONE);
                holder.mIvStatus.setImageResource(R.mipmap.ic_ask_to_buy_disagree);
                break;
        }
    }

    @Override
    public String getDisplayItemTag() {
        return MyJoinedAskListItem.class.getSimpleName();
    }

    @Override
    public Class<MyJoinedAskHolder> getViewHolderClazz() {
        return MyJoinedAskHolder.class;
    }
}
